using FireStarterModeller.BO;
using FireStarterModeller.UI;
using Habanero.Faces.Base;
using Habanero.Faces.Win;
using Habanero.Util;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public  class TestDMClassAllDetailsControl
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }

        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();
        }

        [Test]
        public void Test_CreateControl()
        {
            //---------------Set up test pack-------------------
            IControlFactory controlFactory = new ControlFactoryWin();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            DMClassAllDetailsControl control = CreateDMClassAllDetailsControl(controlFactory);
            //---------------Test Result -----------------------
            Assert.AreSame(controlFactory, control.ControlFactory);
            Assert.AreEqual(3, control.Controls.Count);
            Assert.IsNotNull(control.DMSolutionControl);
            Assert.IsNotNull(control.EditorControl);
            Assert.IsInstanceOf(typeof(DMClassDetailEditorControl), control.EditorControl);
        }

        private static DMClassAllDetailsControl CreateDMClassAllDetailsControl(IControlFactory controlFactory)
        {
            FireStarterFormsController formsController = new FireStarterFormsControllerStub(controlFactory);
            return new CrossThreadRunner().RunInSTA(() => new DMClassAllDetailsControl(controlFactory, formsController));
        }

        [Test]
        public void TestSetDMSolution()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution  = new DMSolution();
            DMClassAllDetailsControl control = CreateDMClassAllDetailsControl(new ControlFactoryWin());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            control.Solution = dmSolution;
            //---------------Test Result -----------------------
            Assert.AreSame(dmSolution, control.Solution);
            Assert.AreSame(dmSolution, control.EditorControl.Solution);
        }

//TODO  26 Mar 2009: 
//        [Test]
//        public void TestDmClassSelected_SetsClassOnCollapsiblePanelGroupControl()
//        {
//            //---------------Set up test pack-------------------
//            DMClass info = TestUtilsShared.CreateSavedDMClass();
//            DMClassAllDetailsControl control = new DMClassAllDetailsControl();
//            control.Solution = info.Solution;
//            //---------------Execute Test ----------------------
//            ((DMSolutionControl)control.DMSolutionControl).ClassSelectorControl.SelectedBusinessObject = info;
//            //---------------Test Result -----------------------
//            Assert.AreSame(info, control.EditorControl.DMClass);
//        }

        //[Test]
        //public void Test_DeleteClass()
        //{
        //    //--------------- Set up test pack ------------------
        //    DMClass dmClass = TestUtilsShared.CreateUnsavedValidDMClass();
        //    DMSolution solution = dmClass.Solution;
        //    DMAssembly assembly = dmClass.Assembly;
        //    DMClassAllDetailsControl control = new DMClassAllDetailsControl();
        //    control.Solution = solution;
        //    DMClassDetailEditorControl collapsiblePanelGroupControl = control.EditorControl;
        //    collapsiblePanelGroupControl.DMClass = dmClass;
        //    IPanel selectorPanel = (IPanel)control.DMSolutionControl.Controls[0];
        //    IButtonGroupControl buttonGroupControl = (IButtonGroupControl)selectorPanel.Controls[1];
        //    //--------------- Test Preconditions ----------------
        //    Assert.IsNotNull(collapsiblePanelGroupControl.DMClass);
        //    Assert.AreSame(dmClass, collapsiblePanelGroupControl.DMClass);
        //    Assert.AreEqual(1, assembly.Classes.Count);
        //    Assert.AreEqual(0, assembly.Classes.MarkedForDeleteBusinessObjects.Count);
        //    //--------------- Execute Test ----------------------
        //    buttonGroupControl["Delete"].PerformClick();
        //    //--------------- Test Result -----------------------
        //    Assert.IsTrue(dmClass.Status.IsDeleted);
        //    Assert.AreEqual(0, assembly.Classes.Count);
        //    Assert.AreEqual(0, assembly.Classes.MarkedForDeleteBusinessObjects.Count);
        //}

        //[Test]
        //public void Test_NoClassSelected_ShouldNotRaiseError()
        //{
        //    //--------------- Set up test pack ------------------
        //    DMClassAllDetailsControl control = CreateDMClassAllDetailsControl(new ControlFactoryWin());
        //    control.Solution = new DMSolution();
        //    DMClassDetailEditorControl editorControl = control.EditorControl;
        //    IPanel selectorPanel = (IPanel)control.DMSolutionControl.Controls[0];
        //    IButtonGroupControl buttonGroupControl = (IButtonGroupControl)selectorPanel.Controls[2];
        //    //--------------- Test Preconditions ----------------
        //    Assert.IsNull(editorControl.DMClass);
        //    //--------------- Execute Test ----------------------
        //    buttonGroupControl["Delete"].PerformClick();
        //    //--------------- Test Result -----------------------
        //    Assert.IsNull(editorControl.DMClass);
        //}

    }
}